package com.example.sls.mapper.student;

import com.example.sls.pojo.student.Student;
import org.apache.ibatis.annotations.*;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface StudentMapper {

    //通过班级号获取该班级所有学生
    @Select("select * from student where cId = #{classId}")
    List<Student> getStudentsByCId(@Param("classId") Integer classId);

    //查看所有未加入班级的学生
    @Select("select * from student where cid = -1")
    List<Student> getStudentWithoutClass();

    //从学生表中获取班级id为cId的学生人数
    @Select("select count(*) from student where cId = #{CId} ; ")
    Integer getCountByCId(@Param("CId")Integer CId);


    //更改学生的cId(教师添加完学生到当前班级后, 当前学生的classId设置为cId)
    @Update("update student set cId = #{cId} where studentId = #{studentId}; ")
    Integer updateCIdBySId(@Param("cId") Integer cId, @Param("studentId") Integer studentId);

    //通过id获取学生信息
    @Select("select * from student where studentId = #{id}")
    Student getStudentInfoById(@Param("id") Integer id);

    @Select("select * from student")
    List<Student> getStudentsInfo();

    @Insert("insert into student(id, studentId, name,cId ) values(#{id},#{studentId},#{name}, #{cId});")
    Integer addStudent(Student student);

    @Update("update student set cId = -1 where studentId = #{studentId}")
    Integer leaveClass(@Param("studentId") Integer studentId);

    @Select("select max(id) from student;")
    Integer getMaxId();

    @Select("select count(*) from student;")
    Integer getCount();

    @Select("select cId from student where studentId = #{studentId}")
    Integer getCIdBySId(@Param("studentId") Integer studentId);


}
